package main

import (
	"fmt"
)

func main() {
	// 编写一个函数实现顺序遍历map中的元素
	var maps = map[string]string{"France": "Paris", "Italy": "Rome", "Japan": "Tokyo", "India": "New delhi"}
	ShowMap(maps)
}

//根据key从小到大遍历map数组
func ShowMap(maps map[string]string) {
	var arr = make([]string, len(maps))
	var num = 0
	for key, _ := range maps {
		arr[num] = key
		num++
	}
	for i := 0; i < len(arr)-1; i++ {
		for j := 0; j < len(arr)-i-1; j++ {
			if GetRe(arr[j], arr[j+1]) {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		}
	}
	for i := 0; i < len(arr); i++ {
		fmt.Println(maps[arr[i]])
	}
}

//byte和
func GetRe(istr string, jstr string) bool {
	var isok = false
	var bistr = []byte(istr)
	var bjstr = []byte(jstr)
	var bisum int
	var bjsum int
	for i := 0; i < len(bistr); i++ {
		bisum += int(bistr[i])
	}
	for i := 0; i < len(bjstr); i++ {
		bjsum += int(bjstr[i])
	}
	if bisum < bjsum {
		isok = true
	}
	return isok
}
